package com.samsung.service.impl.vote;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.samsung.dao.vote.TopicMapper;
import com.samsung.dao.vote.VoteHistoryDtoMapper;
import com.samsung.dto.vote.VoteHistoryDto;
import com.samsung.model.vote.VoteOption;
import com.samsung.model.vote.VoteTopic;
import com.samsung.service.vote.TopicService;
@Service("topicService")
public class TopicServiceImpl implements TopicService {
	@Autowired
	private TopicMapper topicMapper;
	@Autowired
	private VoteHistoryDtoMapper voteHistoryDtoMapper;
	@Override
	public int deleteByPrimaryKey(String oid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insert(VoteOption record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insertSelective(VoteOption record) {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * 查询Option对象
	 */
	@Override
	public VoteOption selectByPrimaryKey(String oid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updateByPrimaryKeySelective(VoteOption record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(VoteOption record) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@Override
	public List<VoteTopic> listNewVote(int max) {
		return topicMapper.listNewVote(max);
	}

	@Override
	public List<VoteHistoryDto> listHotVote(int max) {
		return voteHistoryDtoMapper.listHotVote(max);
	}
	/**
	 * 查询Topic对象
	 */
	public VoteTopic getTopic(String tid){
		return  topicMapper.selectByPrimaryKey(tid);
	}

	@Override
	public List<Map<String, Object>> getVoteList(Map<String, Object> condition) {
		return topicMapper.getVoteList(condition);
	}
	
	@Override
	public Integer getVoteCount(Map<String, Object> condition) {
		return topicMapper.getVoteCount(condition);
	}

	@Override
	public List<Map<String, Object>> getMyJoinList(Map<String, Object> condition) {
		return topicMapper.getMyJoinList(condition);
	}

	@Override
	public Integer getMyJoinCount(Map<String, Object> condition) {
		return topicMapper.getMyJoinCount(condition);
	}

	@Override
	public Map<String, Object> getTopicById(String topicId) {
		return topicMapper.getTopicById(topicId);
	}

	@Override
	public List<Map<String, Object>> getOptionList(Map<String, Object> condition) {
		return topicMapper.getOptionList(condition);
	}

	@Override
	public List<Map<String, Object>> getVoteResult(String topicId) {
		return topicMapper.getVoteResult(topicId);
	}

	@Override
	public Integer getMyCreateCount(Map<String, Object> condition) {
		return topicMapper.getMyCreateCount(condition);
	}

	@Override
	public List<Map<String, Object>> getMyCreateList(Map<String, Object> condition) {
		return topicMapper.getMyCreateList(condition);
	}

	@Override
	public List<List<Object>> getVoteResultList(String topicId) {
		List<Map<String, Object>> maps = topicMapper.getVoteResultList(topicId);
		List<List<Object>> lists = new ArrayList<List<Object>>();
		List<Object> list;
		for (Map<String, Object> map : maps) {
			list = new ArrayList<Object>();
			list.add(map.get("title"));
			list.add(map.get("type"));
			list.add(map.get("scope"));
			list.add(map.get("singleId"));
			list.add(map.get("name"));
			list.add(map.get("content"));
			list.add(map.get("create_time"));
			lists.add(list);
		}
		return lists;
	}
}
